package com.xu.fountain.Config;

import com.xu.fountain.Util.Result;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

/**
 * @Message: created by XUBO on 2018/4/31
 * @Description:
 */

public class ApiInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        System.out.println( "拦截了api" );
        OutputStream out = null;
        response.setCharacterEncoding( "utf-8" );
        response.setContentType( "text/json");
        out = response.getOutputStream();
        Result MSG = new Result(1,"拦截了",null );

        out.write( MSG.toString().getBytes("utf-8"));
        out.flush();
        return true;
    }
}
